from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-28 14:14:22.851462
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 28, Sep, 2022
Time: 14:14:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.5293
Nobs: 793.000 HQIC: -50.8560
Log likelihood: 10208.3 FPE: 6.68273e-23
AIC: -51.0599 Det(Omega_mle): 5.96998e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298791 0.053483 5.587 0.000
L1.Burgenland 0.108872 0.035740 3.046 0.002
L1.Kärnten -0.106398 0.019014 -5.596 0.000
L1.Niederösterreich 0.207951 0.074698 2.784 0.005
L1.Oberösterreich 0.102695 0.071739 1.432 0.152
L1.Salzburg 0.251731 0.038109 6.605 0.000
L1.Steiermark 0.037809 0.049867 0.758 0.448
L1.Tirol 0.106156 0.040405 2.627 0.009
L1.Vorarlberg -0.058824 0.034750 -1.693 0.091
L1.Wien 0.055596 0.064187 0.866 0.386
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060325 0.110842 0.544 0.586
L1.Burgenland -0.033126 0.074071 -0.447 0.655
L1.Kärnten 0.047861 0.039406 1.215 0.225
L1.Niederösterreich -0.170952 0.154811 -1.104 0.269
L1.Oberösterreich 0.384204 0.148677 2.584 0.010
L1.Salzburg 0.287791 0.078981 3.644 0.000
L1.Steiermark 0.107054 0.103348 1.036 0.300
L1.Tirol 0.313582 0.083739 3.745 0.000
L1.Vorarlberg 0.025607 0.072020 0.356 0.722
L1.Wien -0.015589 0.133026 -0.117 0.907
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191897 0.027497 6.979 0.000
L1.Burgenland 0.089642 0.018375 4.878 0.000
L1.Kärnten -0.008120 0.009776 -0.831 0.406
L1.Niederösterreich 0.261792 0.038405 6.817 0.000
L1.Oberösterreich 0.128380 0.036883 3.481 0.001
L1.Salzburg 0.046379 0.019593 2.367 0.018
L1.Steiermark 0.018166 0.025638 0.709 0.479
L1.Tirol 0.092967 0.020774 4.475 0.000
L1.Vorarlberg 0.059740 0.017866 3.344 0.001
L1.Wien 0.120161 0.033001 3.641 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.106923 0.028128 3.801 0.000
L1.Burgenland 0.044686 0.018797 2.377 0.017
L1.Kärnten -0.016014 0.010000 -1.601 0.109
L1.Niederösterreich 0.193492 0.039286 4.925 0.000
L1.Oberösterreich 0.293424 0.037730 7.777 0.000
L1.Salzburg 0.115149 0.020043 5.745 0.000
L1.Steiermark 0.100862 0.026227 3.846 0.000
L1.Tirol 0.115909 0.021250 5.454 0.000
L1.Vorarlberg 0.071238 0.018276 3.898 0.000
L1.Wien -0.025910 0.033758 -0.768 0.443
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130644 0.051035 2.560 0.010
L1.Burgenland -0.051808 0.034104 -1.519 0.129
L1.Kärnten -0.039978 0.018144 -2.203 0.028
L1.Niederösterreich 0.169428 0.071280 2.377 0.017
L1.Oberösterreich 0.139880 0.068456 2.043 0.041
L1.Salzburg 0.285107 0.036365 7.840 0.000
L1.Steiermark 0.035235 0.047585 0.740 0.459
L1.Tirol 0.163015 0.038556 4.228 0.000
L1.Vorarlberg 0.104150 0.033160 3.141 0.002
L1.Wien 0.066611 0.061249 1.088 0.277
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.057187 0.040445 1.414 0.157
L1.Burgenland 0.038633 0.027027 1.429 0.153
L1.Kärnten 0.050786 0.014379 3.532 0.000
L1.Niederösterreich 0.224586 0.056488 3.976 0.000
L1.Oberösterreich 0.281515 0.054250 5.189 0.000
L1.Salzburg 0.050615 0.028819 1.756 0.079
L1.Steiermark -0.005412 0.037710 -0.144 0.886
L1.Tirol 0.149327 0.030555 4.887 0.000
L1.Vorarlberg 0.072074 0.026279 2.743 0.006
L1.Wien 0.081669 0.048539 1.683 0.092
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178923 0.048387 3.698 0.000
L1.Burgenland -0.006230 0.032335 -0.193 0.847
L1.Kärnten -0.061036 0.017202 -3.548 0.000
L1.Niederösterreich -0.083803 0.067582 -1.240 0.215
L1.Oberösterreich 0.192890 0.064904 2.972 0.003
L1.Salzburg 0.056659 0.034479 1.643 0.100
L1.Steiermark 0.231279 0.045116 5.126 0.000
L1.Tirol 0.493356 0.036556 13.496 0.000
L1.Vorarlberg 0.049653 0.031440 1.579 0.114
L1.Wien -0.049328 0.058072 -0.849 0.396
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158713 0.055554 2.857 0.004
L1.Burgenland -0.011217 0.037124 -0.302 0.763
L1.Kärnten 0.066086 0.019750 3.346 0.001
L1.Niederösterreich 0.201097 0.077591 2.592 0.010
L1.Oberösterreich -0.061429 0.074517 -0.824 0.410
L1.Salzburg 0.215420 0.039586 5.442 0.000
L1.Steiermark 0.114754 0.051798 2.215 0.027
L1.Tirol 0.076370 0.041970 1.820 0.069
L1.Vorarlberg 0.124986 0.036096 3.463 0.001
L1.Wien 0.117462 0.066673 1.762 0.078
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.355406 0.032264 11.016 0.000
L1.Burgenland 0.006953 0.021560 0.322 0.747
L1.Kärnten -0.023493 0.011470 -2.048 0.041
L1.Niederösterreich 0.222784 0.045062 4.944 0.000
L1.Oberösterreich 0.176337 0.043277 4.075 0.000
L1.Salzburg 0.046783 0.022990 2.035 0.042
L1.Steiermark -0.018210 0.030082 -0.605 0.545
L1.Tirol 0.108440 0.024374 4.449 0.000
L1.Vorarlberg 0.073432 0.020963 3.503 0.000
L1.Wien 0.052777 0.038721 1.363 0.173
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041089 0.152451 0.191402 0.157468 0.125060 0.113935 0.065877 0.224494
Kärnten 0.041089 1.000000 -0.003358 0.129375 0.041109 0.095837 0.429581 -0.053435 0.101675
Niederösterreich 0.152451 -0.003358 1.000000 0.335650 0.155404 0.298492 0.110562 0.182021 0.323912
Oberösterreich 0.191402 0.129375 0.335650 1.000000 0.231705 0.332737 0.172377 0.171772 0.264185
Salzburg 0.157468 0.041109 0.155404 0.231705 1.000000 0.145614 0.126461 0.148467 0.135292
Steiermark 0.125060 0.095837 0.298492 0.332737 0.145614 1.000000 0.152509 0.140107 0.080275
Tirol 0.113935 0.429581 0.110562 0.172377 0.126461 0.152509 1.000000 0.114227 0.154227
Vorarlberg 0.065877 -0.053435 0.182021 0.171772 0.148467 0.140107 0.114227 1.000000 0.006875
Wien 0.224494 0.101675 0.323912 0.264185 0.135292 0.080275 0.154227 0.006875 1.000000